<?php
error_reporting(0);
session_start();
include("common/config.php");
$conn=new connectDb();
date_default_timezone_set('PRC');

function page($chaxun,$page,$pagenum,$cs){  
 //$hwnd表示连接数据库的句柄  $chaxun表示查询的条件 $page表示网页文件名 $pagenum表示每页显示的记录条数
			$chaxun=$chaxun;		
			mysql_query("SET NAMES 'utf8'");			
            $resu=mysql_query($chaxun);
			$nums=mysql_num_rows($resu);
			if($nums!=0){
			@$ye=$_GET['ye'];	
			$pagenum=$pagenum;
			$page=$page;
            $gye=ceil($nums/$pagenum);
            if($gye==0){$gye=1;}
            if($ye=="" || $gye<$ye){$ye=1;}
            echo "共".$gye."页&nbsp;";			
            if($ye!=1){
            $yeb=$ye-1;
            echo "<a href='$page?ye=1$cs'>首页</a>";
            }
            if($ye!=$gye){
            $yen=$ye+1;
            echo "&nbsp;<a href='$page?ye=$gye$cs'>末页</a>";
            }
			echo "&nbsp;";
			
			$pageflag=6;               //每块显示多少页
			$page_r=ceil($gye/$pageflag);//分多少块显示
			$k=ceil($ye/$pageflag);
			if($k==1)echo "<a href='$page?ye=$k$cs'> << </a>&nbsp;";
			  else{
			    $m=($k-1)*$pageflag-4;
			  	echo "<a href='$page?ye=$m$cs'> << </a>&nbsp;";
			  }  
			if($k<$page_r)$n=$pageflag;
			 else $n=$gye-($k-1)*$pageflag;
			for($i=1;$i<=$n;$i++){					
			    $k_1=($k-1)*$pageflag+$i;
				if($k_1==$ye){
					echo "<a href='$page?ye=$k_1$cs'>$k_1</a>&nbsp;";
				}
				else{
					echo "<a href='$page?ye=$k_1$cs'>[$k_1]</a>&nbsp;";
				}
				
			}
			if($k==$page_r){
				echo "<a href='$page?ye=$gye$cs'> >> </a>&nbsp;";
			}
			  else{
			    $m=$k*$pageflag+1;
			  	echo "<a href='$page?ye=$m$cs'> >> </a>&nbsp;";
			  } 
			$lim1=($ye-1)*$pagenum;
			$chaxun=$chaxun." limit $lim1,$pagenum";
			if($gye>10){
			?>
			<form style="display:inline;" method="POST">
			到&nbsp;<input name="inputye" type="text" class="flip_input" />&nbsp;页<input type="submit" name="inputsub" value="跳转" class="flip_btn" />
		</form>
			<?php
		}
			if(@$_POST[inputsub]){
			echo "<script language=javascript>\n";
			echo "window.location.href='$page?ye=$_POST[inputye]$cs'";
			echo "</script>\n";
			}
		}else{
			echo "<div class=\"report_noData mt50 tc f20\">Sorry ˇ_ˇ ！暂时没有你的私信~</div>";
			}
			return(@$gye);			
}

function page_r($chaxun,$page,$pagenum,$cs){  
			$chaxun=$chaxun;
			mysql_query("SET NAMES 'utf8'");
            $resu=mysql_query($chaxun);			
			$nums=mysql_num_rows($resu);
			@$ye=$_GET['ye'];	
			$pagenum=$pagenum;
			$page=$page;
            $gye=ceil($nums/$pagenum);			
            if($gye==0){$gye=1;}			
            if($ye=="" || $gye<$ye){$ye=1;}			
			$lim1=($ye-1)*$pagenum;
			$chaxun=$chaxun." limit $lim1,$pagenum";
			return($chaxun);
}

	
	
function fixlen($str,$len){

		$i = 0;    
    $tlen = 0;    
    $tstr = '';    
    while ($tlen < $len) {    
        $chr = mb_substr($str, $i, 1, 'utf8');    
        $chrLen = ord($chr) > 127 ? 2 : 1;    
        if ($tlen + $chrLen > $len) break;    
        $tstr .= $chr;    
        $tlen += $chrLen;    
        $i ++;    
    }    
    if ($tstr != $str) {    
        $tstr .= '......';    
    }    
    return htmlspecialchars($tstr,utf-8);
		}
		
		
function dirReader($dir){
	$handle=opendir($dir);
	$i=0;
	while($file=readdir($handle))   {
		if   (($file!= ".")and($file!= ".."))   {
		$list[$i]=$file;
		$i=$i+1;
		}
	}
	closedir($handle);  
	return   $list;
}



function checkSql($str){

	//$str=trim($str);
 	//$str=strip_tags($str);
 	//$str=stripslashes($str);
 	//$str=addslashes($str);
 	//$str=rawurldecode($str);
 	//$str=quotemeta($str);
 	//$str=htmlspecialchars($str);
 	$str=preg_replace("/\+|\*|\`|\/|\-|\$|\#|\^|\!|\@|\%|\&|\~|\^|\[|\]|\'|\"|\<|\>|\=/", "", $str);
 	//去除特殊符号+*`/-$#^~!@#$%&[]'"
 	//$str=preg_replace("//s/", "", $str);//去除空格、换行符、制表符
 	return $str;

}

function cutphoto($o_photo,$d_photo,$width,$height){ 
	$temp_img = imagecreatefromjpeg($o_photo); 
	$o_width  = imagesx($temp_img);                                //取得原图宽 
	$o_height = imagesy($temp_img);                                //取得原图高 	
	//判断处理方法 
	if($width>$o_width || $height>$o_height){        //原图宽或高比规定的尺寸小,进行压缩 	
		$newwidth=$o_width; 
		$newheight=$o_height; 	
		if($o_width>$width){ 
		        $newwidth=$width; 
		        $newheight=$o_height*$width/$o_width; 
		} 	
		if($newheight>$height){ 
		        $newwidth=$newwidth*$height/$newheight; 
		        $newheight=$height; 
		} 	
		//缩略图片 
		$new_img = imagecreatetruecolor($newwidth, $newheight);  
		imagecopyresampled($new_img, $temp_img, 0, 0, 0, 0, $newwidth, $newheight, $o_width, $o_height);  
		imagejpeg($new_img , $d_photo);                 
		imagedestroy($new_img); 	
	}else{                                                                                //原图宽与高都比规定尺寸大,进行压缩后裁剪 
	  if($o_height*$width/$o_width>$height){        //先确定width与规定相同,如果height比规定大,则ok 
	          $newwidth=$width; 
	          $newheight=$o_height*$width/$o_width; 
	          $x=0; 
	          $y=($newheight-$height)/2; 
	  }else{                                                                        //否则确定height与规定相同,width自适应 
	          $newwidth=$o_width*$height/$o_height; 
	          $newheight=$height; 
	          $x=($newwidth-$width)/2; 
	          $y=0; 
	  } 	
	  //缩略图片 
	  $new_img = imagecreatetruecolor($newwidth, $newheight);  
	  imagecopyresampled($new_img, $temp_img, 0, 0, 0, 0, $newwidth, $newheight, $o_width, $o_height);  
	  imagejpeg($new_img , $d_photo);                 
	  imagedestroy($new_img); 
	  	         
	  $temp_img = imagecreatefromjpeg($d_photo); 
	  $o_width  = imagesx($temp_img);                                //取得缩略图宽 
	  $o_height = imagesy($temp_img);                                //取得缩略图高 
	
	  //裁剪图片 
	  $new_imgx = imagecreatetruecolor($width,$height); 
	  imagecopyresampled($new_imgx,$temp_img,0,0,$x,$y,$width,$height,$width,$height); 
	  imagejpeg($new_imgx , $d_photo); 
	  imagedestroy($new_imgx); 
	} 
}

//返回用户头相的地址
function showUserPhoto(){
	$src="image.php?user_mail=".$_SESSION['login_mail'];
	return $src;
	}

function shareUserPhoto($user_mail){
	$src="image.php?user_mail=".$user_mail;
	return $src;
	}

//返回用户名
function showUserName(){
	$user=$_SESSION['login_mail'];
	$re=mysql_query("select * from food_user_basic where user_mail='$user'");
	$row=mysql_fetch_array($re);
	return $row['nick'];
	}

//返回用户示读私信数量
function showCountMassage($user){
	$result=mysql_query("select * from food_massage where to_user='$user' and `condition`=0 and `del`='0'")or die(mysql_error());
	$row=mysql_num_rows($result);
	return $row;
	}
	
//返回用户地址 
function showUserCity($user){
	$re=mysql_query("select * from food_user_basic where user_mail='$user'");
	$row=mysql_fetch_array($re);
	return $row['user_city'];
	}


function scanMassage($user){
	$result=mysql_query("select * from food_user_basic where user_mail='$user'");
	$row=mysql_fetch_array($result);
	$time=time()-24*3600*30;
	//$date=date("Y-m-d",$time);
	$sql="select * from food_caiji_zccw where `area` like '%$row[user_city]%' or news_title like '%$row[user_city]%' order by news_time desc";
	//echo $sql;exit();
	$re=mysql_query($sql)or die(mysql_error());
	while($row=mysql_fetch_array($re)){
		//echo $row['news_title'];
		if(mktime(0,0,0,intval(substr($row['news_time'],5,2)),intval(substr($row['news_time'],8,2)),intval(substr($row['news_time'],0,4))) < $time)break;
		$content=$row['news_time']."&nbsp&nbsp&nbsp"."<a target='_blank' href='".$row['news_link']."'>".$row['news_title']."</a>";
		$content=mysql_escape_string($content);
		$r=mysql_query("select * from food_massage where `content`='$content'");
		$count=mysql_num_rows($r);		
		if($count==0){
			$x=mysql_query("insert into food_massage (id,from_user,to_user,content,post_time,`condition`,`del`)values(null,'系统','$user','$content','$row[news_time]',0,0)")or die(mysql_error());
			}
		
		}
	}

//专门针对形如：[名称]=>[值]的数组进行转换
function changeArray($array){
	//$i=0;
	foreach($array as $name => $value){
		$arr[] = array($name,$value);
		}
		return $arr;
	}
	
//图片入库
function imageStorage($picture){
	if(file_exists($picture)){
		$PSize = filesize($picture);
  	$mysqlPicture = addslashes(fread(fopen($picture,"r"), $PSize));
  	$user=$_SESSION['login_mail'];
  	mysql_query("update food_user_basic set photo='$mysqlPicture' where user_mail='$user'") or die(mysql_error()); 
 	} else {
		echo "<script language=\"javascript\">alert('未知错误');</script>";
 	}
}
	

//判断登陆	
function judgeLogin()
{
	if(empty($_SESSION['login_mail']))
	{
		echo "<script language=\"javascript\">location.href='login.php';</script>";
	}

}

//判断用户是否为第一次登录
function judgeNewUser($login_mail)
{
	$query = mysql_query("SELECT * FROM `food_user_basic` WHERE `user_mail` = '".$login_mail."' ORDER BY `id` DESC") or die(mysql_error());
	$row = mysql_fetch_array($query);
	$login_status = $row['login_status'];
	
	return $login_status;
}

//新人登陆必填信息 
if(isset($_POST['submited']))
{	
	$fileName = $_POST['fileName'];
	$sex = $_POST['sex'];
	$age = (int)$_POST['age'];
	$city = $_POST['city'];
	$weight =(int)$_POST['weight'];
	
	if($sex == '男' || $sex == '女')
	{
		if($age < 200 && $age >0)
		{
			if($weight < 300 && $weight >0)
			{
				//$sql_photo = "SELECT `photo` FROM `food_user_basic` WHERE `user_mail` = '".$_SESSION['login_mail']."'";
				//$query_photo = mysql_query($sql_photo) or die(mysql_error());
				//$num_photo = mysql_num_rows($query_photo);
				//$row_photo = mysql_fetch_array($query);
				//if($num_photo != 0 && !empty($row_photo['photo']))
				//{
					$query = mysql_query("UPDATE `food_user_basic` SET `user_sex` = '".$sex."',`user_age` = '".$age."',`user_city` = '".$city."' ,`weight` = '".$weight."',`login_status` = '1' WHERE `user_mail` = '".$_SESSION['login_mail']."'" ) or die(mysql_error());
					if($query)
					{
						header("Location:$fileName"); 
						return true;
					}else
					{
						return false;
					}
				//}else
				//{
				//	return false;
				//}
			}else
			{
				return false;
			}
		}else
		{
			return false;
		}
	}else
	{
		return false;
	}

} 


//获取用户基本信息
function getUserBasicInfo($user_mail)
{
	$query = mysql_query("SELECT * FROM `food_user_basic` WHERE `user_mail` = '".$user_mail."' ORDER BY `id` DESC") or die(mysql_error());
	
	$row = mysql_fetch_array($query);
	
	$data = array('user_sex'=>$row['user_sex'],'weight'=>$row['weight'],'user_age'=>$row['user_age'],'user_city'=>$row['user_city']);
	
	return $data;
}


//获得用户体重数据
function getUserWeight($username)
{
	$query = mysql_query("SELECT * FROM `food_user_basic` WHERE `nick` = '".$username."' ORDER BY `id` ASC");
	
	$row = mysql_fetch_array($query);
	
	return $row['weight'];
}

//得到用户名
function getUserNick($user_mail)
{
	$query = mysql_query("SELECT * FROM `food_user_basic` WHERE `user_mail` = '".$user_mail."' ORDER BY `id` DESC") or die(mysql_error());
	
	$row = mysql_fetch_array($query);
	
	$nick = $row['nick'];
	
	return $nick;
}

//得到用户ID
function getUserId($user_mail)
{
	$query = mysql_query("SELECT * FROM `food_user_basic` WHERE `user_mail` = '".$user_mail."' ORDER BY `id` DESC") or die(mysql_error());
	
	$row = mysql_fetch_array($query);
	
	$user_id = $row['id'];
	
	return $user_id;
}

//获得用户今日已经吃过的食物名称
function getUserEatFoodName($username)
{
 	$user_id = getUserId($_SESSION['login_mail']);
	//当前时间
	$sqltime = mysql_query("SELECT `create_time` FROM `food_user_basic` WHERE `id` = '$user_id'") or die(mysql_error());
	$rowtime = mysql_fetch_array($sqltime,MYSQL_ASSOC);
	$todayDate = substr($rowtime['create_time'],0,10); 

    $foodName = array();
	
	$sql = "SELECT * FROM `food_basic` 
			INNER JOIN `food_user_data` ON `food_user_data`.`eatwhat` = `food_basic`.`ch_name`
			INNER JOIN `food_user_basic` ON `food_user_basic`.`id` =  `food_user_data`.`user_id`
			WHERE `food_user_basic`.`nick` = '".$username."' AND `food_user_data`.`history_data` = '0' ORDER BY `food_basic`.`id` ASC";
			
	$query = mysql_query($sql) or die(mysql_error());
	//echo $numLimit = mysql_num_rows($query);
	while($row = mysql_fetch_array($query))
	{
		$createTime = substr($row['create_time'],0,10);
		if($todayDate == $createTime):
		$foodName[] = $row['ch_name'];
		endif;
	}
	
	return $foodName;
}
	
//得到用户食用的上限值 体重*adi
function getLimitValue($weight,$foodName)
{
	$sqlLimit = "SELECT * FROM `food_additive` 
				 INNER JOIN `food_basic_additive_rel` ON `food_additive`.`id` = `food_basic_additive_rel`.`additive_id` 
				 INNER JOIN `food_basic` ON `food_basic_additive_rel`.`basic_id` = `food_basic`.`id`
				 WHERE `food_basic`.`ch_name` = '".$foodName."'";
				
	$queryLimit = mysql_query($sqlLimit) or die(mysql_error());
    
	$numLimit = mysql_num_rows($queryLimit);
	//echo "<br>";
	if($numLimit > 0)
	{
		for($i=1;$i<=$numLimit;$i++)
		{
			$rowLimit = mysql_fetch_array($queryLimit,MYSQL_ASSOC);
			
			$adiValue = $rowLimit['adi'];

			$weight = $weight;
			
			//计算添加剂的上限量
			//如果adi为0，说明该食物的最大限量不做限定，人为赋值
			if($adiValue == 0): $adiValue = 100; endif;
			
			$limitValue = $weight*$adiValue;
			
			$ch_name = $rowLimit['additive_ch_name'];
			
			$data[$ch_name] = $limitValue;
			
			//print_r($data);
		}
		
		return $data;
	}
}
	
	
//取得食物的净含量和食物名称
function getActualNetcontent($username)
{
	$user_id = getUserId($_SESSION['login_mail']);
	//当前时间
	$sqltime = mysql_query("SELECT `create_time` FROM `food_user_basic` WHERE `id` = '$user_id'") or die(mysql_error());
	$rowtime = mysql_fetch_array($sqltime,MYSQL_ASSOC);
	$todayDate = substr($rowtime['create_time'],0,10); 
	
	$data = array();
	
	$sql = "SELECT `food_basic`.`ch_name`,`food_user_data`.`eathowmany`,`food_user_data`.`create_time`
			FROM `food_user_data` 
			INNER JOIN `food_user_basic` ON `food_user_basic`.`id` = `food_user_data`.`user_id`
			INNER JOIN `food_basic` ON `food_user_data`.`eatwhat` = `food_basic`.`ch_name`
			WHERE `food_user_basic`.`nick` = '".$username."' AND `food_user_data`.`history_data` = '0'
			ORDER BY `food_user_data`.`id` DESC";

	$query = mysql_query($sql);
	
	while($row = mysql_fetch_array($query,MYSQL_ASSOC))
	{
		$createTime = substr($row['create_time'],0,10);
		if($todayDate == $createTime):
		
		$ch_name = $row['ch_name'];
	
		$data[$ch_name] = (float)$row['eathowmany']; 
		
		endif;
	}
	
	return $data;
}

function getActualValue($foodNameValue,$netcontent)
{
	//查询该种食品所有的添加剂在其所属类别中的最大使用量 
	$sqlActualMax = "SELECT * FROM `food_basic_additive_rel` 
					INNER JOIN `food_basic` ON `food_basic`.`id` = `food_basic_additive_rel`.`basic_id`
					INNER JOIN `food_maxuse` ON `food_maxuse`.`additive_id` = `food_basic_additive_rel`.`additive_id`
					AND `food_basic`.`category_id` = `food_maxuse`.`category_id`
					INNER JOIN `food_additive` ON `food_additive`.`id` = `food_maxuse`.`additive_id`
					WHERE `food_basic`.`ch_name` = '".$foodNameValue."'";	
					
	$queryActualMax = mysql_query($sqlActualMax) or die(mysql_error());
	
	$numActualMax = mysql_num_rows($queryActualMax);
	//echo "<br>";
	//添加剂在某种种类中的最大使用量不存在，返回该添加剂在某种种类中的实际摄入量为0
	if($numActualMax > 0)
	{
		for($i=1;$i<=$numActualMax;$i++)
		{
			$rowActualMax = mysql_fetch_array($queryActualMax,MYSQL_ASSOC);
		
			$ch_name = $rowActualMax['additive_ch_name'];
			
			$maxUse = $rowActualMax['maxuse'];
		
			//计算添加剂的最大使用量使用
			$actualValue = $netcontent*$maxUse*1000;
			
			$data[$ch_name] = $actualValue;
			
		}//end for $i
	}
	else //在该分类中没有最大使用量，即按生产所需适量使用~随机赋值
	{
		//查处该食物所有的添加剂
		$sql = "SELECT * FROM `food_additive` 
				 INNER JOIN `food_basic_additive_rel` ON `food_additive`.`id` = `food_basic_additive_rel`.`additive_id` 
				 INNER JOIN `food_basic` ON `food_basic_additive_rel`.`basic_id` = `food_basic`.`id`
				 WHERE `food_basic`.`ch_name` = '".$foodNameValue."'";
		$query = mysql_query($sql) or die(mysql_error());
		while($row = mysql_fetch_array($query,MYSQL_ASSOC))
		{
			$ch_name = $row['additive_ch_name'];
			
			$maxUse = 2.0;
			
			//计算添加剂的最大使用量使用
			$actualValue = $netcontent*$maxUse*1000;
			
			$data[$ch_name] = $actualValue;
		}
			//print_r($data);
			//echo "<hr>";
	} 
	
	
	return $data;
}

	
//键名相同的值相加 rebuild a array
function rebuild_array($arr) 
{ 
	static $tmp=array();
  
	foreach($arr as $key=>$val)
	{
		if(is_array($val))
		{
			rebuild_array($val);
		}
		else
		{ 
			if(!isset($tmp[$key]))
			{
				$tmp[$key] = $val;
			}
			else
			{
				$tmp[$key] = $tmp[$key]+$val;
			}
		}
    }
  
    return $tmp;
}


function rebuild_arra($arr) 
{ 
	static $tmmp=array();
  
	foreach($arr as $key=>$val)
	{
		if(is_array($val))
		{
			rebuild_arra($val);
		}
		else
		{ 
			if(!isset($tmmp[$key]))
			{
				$tmmp[$key] = $val;
			}
			else
			{
				$tmmp[$key] = $tmmp[$key]+$val;
			}
		}
    }
  
    return $tmmp;
}

//删除数组空元素
function delArrayRepeat($arr)
{
	if(is_array($arr))
	{
		foreach($arr as $k=>$v)
		{
			if($v == '')
			{
				unset($arr[$k]);
			}
		}
		
		$result = $arr;
   }
   else
   {
	    $result = "参数必需是数组！";
   }
	
	return $result;
}


//得到用户的历史分数
function getUserHistoryScore($userId)
{
	$sql_start = mysql_query("select id from food_user_score where user_id = '".$userId."' ") or die(mysql_error());	
 	$start_num = mysql_num_rows($sql_start);
	if($start_num >= 10):
	$row_start = $start_num - 10;
	else:
	$row_start = 0;
	endif;
	$sql = "SELECT * FROM `food_user_score` WHERE `user_id` = '".$userId."' ORDER BY `create_time` ASC LIMIT $row_start , 10";

	$query = mysql_query($sql) or die(mysql_error());
	
	while($row = mysql_fetch_array($query))
	{
		$create_time = substr($row['create_time'],5,5);
	
		$data[$create_time] = $row['user_score']; 
	}
	
	return $data;

}

//得到用户吃过的各类食物的比重
function getEatedFoodCategoryRate($userId)
{
	//当前时间
	$sqltime = mysql_query("SELECT `create_time` FROM `food_user_basic` WHERE `id` = '$userId'") or die(mysql_error());
	$rowtime = mysql_fetch_array($sqltime,MYSQL_ASSOC);
	$todayDate = substr($rowtime['create_time'],0,10);

	$sql = "SELECT `food_user_data`.`create_time`,`food_user_data`.`eatwhat`,`food_user_data`.`eathowmany`,`food_category`.`category` FROM `food_user_data` INNER JOIN `food_basic` ON `food_basic`.`ch_name` = `food_user_data`.`eatwhat` INNER JOIN
	`food_category` ON `food_category`.`id` = `food_basic`.`category_id` WHERE `food_user_data`.`user_id` = '".$userId."' AND `food_user_data`.`history_data` = '0'";

	$query = mysql_query($sql) or die(mysql_error());
	
	while($row = mysql_fetch_array($query))
	{
		$createTime = substr($row['create_time'],0,10);
		
		if($todayDate == $createTime):
			$data[] = array($row['category']=>$row['eathowmany']);
		endif;
	}
	
	return $data;
}

//得到用户今日的分数和提示语
function getUserHistoryScoreTip($userId,$username)
{

	//当前时间
	$sqltime = mysql_query("SELECT `create_time` FROM `food_user_basic` WHERE `id` = '$userId'") or die(mysql_error());
	$rowtime = mysql_fetch_array($sqltime,MYSQL_ASSOC);
	$todayDate = substr($rowtime['create_time'],0,10);
	
	//用户今日的饮食不为空
	$sqlFood = "SELECT * FROM `food_basic` 
			INNER JOIN `food_user_data` ON `food_user_data`.`eatwhat` = `food_basic`.`ch_name`
			INNER JOIN `food_user_basic` ON `food_user_basic`.`id` =  `food_user_data`.`user_id`
			WHERE `food_user_basic`.`nick` = '".$username."' AND `food_user_data`.`history_data` = '0' ORDER BY `food_basic`.`id` ASC";
			
	$queryFood = mysql_query($sqlFood) or die(mysql_error());
	
	$numFood = mysql_num_rows($queryFood);
	if( $numFood != 0 ):	
	$sql_start = mysql_query("select id from food_user_score where user_id = '".$userId."' ") or die(mysql_error());	
 	$start_num = mysql_num_rows($sql_start);
	if($start_num >= 10):
	$row_start = $start_num - 10;
	else:
	$row_start = 0;
	endif;
	$sql = "SELECT * FROM `food_user_score` WHERE `user_id` = '".$userId."' ORDER BY `create_time` ASC LIMIT $row_start,15";

	$query = mysql_query($sql) or die(mysql_error());
	
	while($row = mysql_fetch_array($query))
	{
		$createTime = substr($row['create_time'],0,10);
		
		if($todayDate == $createTime):
		
	 	$tip = $row['tip'];
	 	$score = $row['user_score']; 
		$data[$score] = $tip;
		
		endif;
	}
	
	endif;
	return $data;

}


function getIP()
{
    static $realip;
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realip = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $realip = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $realip = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $realip = getenv("HTTP_CLIENT_IP");
        } else {
            $realip = getenv("REMOTE_ADDR");
        }
    }

    return $realip;
}

function qq_status($login_mail)
{
	$qq_sql = mysql_query("select `qq_status` from food_user_basic where user_mail = '$login_mail' ");
	$qq_query = mysql_fetch_array($qq_sql);
	return $qq_query['qq_status'];
}
























?>
